import { http } from "@/utils/http";

type ResultTable = {
  total?: number;
  data?: Array<any>;
};

/****** 项目相关接口 */
// 查询项目列表
export const queryItemsList = (data?: Record<string, any>) => {
  return http.request<ResultTable>("post", "/erc/api/v1/maintain/project/queryListPage", {
    data
  });
};

// 新增项目
export const addItems = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/project/create", {
    data
  });
};

// 更新项目
export const updateItems = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/project/update", {
    data
  });
};

// 删除项目
export const delItems = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/project/delete", {
    data
  });
};

/****** 计划相关接口 */
// 查询计划列表
export const queryPlanList = (data?: Record<string, any>) => {
  return http.request<ResultTable>("post", "/erc/api/v1/maintain/plan/queryList", {
    data
  });
};

// 生成单号
export const createPlanCode = () => {
  return http.request("get", "/erc/api/v1/maintain/plan/getPlanCode");
};

// 新增计划
export const addPlan = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/plan/create", {
    data
  });
};

// 更新计划
export const updatePlan = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/plan/update", {
    data
  });
};

// 删除计划
export const delPlan = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/plan/delete", {
    data
  });
};

// 保养计划关联保养设备列表
export const queryPlanEqp = (data?: Record<string, any>) => {
  return http.request<[]>("post", "/erc/api/v1/maintain/planEqp/queryList", {
    data
  });
};

// 保养计划关联保养项目列表
export const queryPlanItems = (data?: Record<string, any>) => {
  return http.request<[]>("post", "/erc/api/v1/maintain/planProject/queryList", {
    data
  });
};

/****** 工单相关接口 */
// 查询工单列表
export const queryOrderList = (data?: Record<string, any>) => {
  return http.request<ResultTable>("post", "/erc/api/v1/maintain/task/queryList", {
    data
  });
};

// 上传检测报告
export const uploadOrderFile = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/task/uploadFile", {
    data
  });
};

// 工单派发
export const allocateOrder = (data?: Record<string, any>) => {
  return http.request("post", "/erc/api/v1/maintain/task/execute", {
    data
  });
};

// 工单上传图片moduleName
export const getModuleName = () => {
  return http.request<string>("post", `/erc/api/v1/maintain/task/getFileModelName`);
};

// 详情
export const queryOrderDetail = (data?: string) => {
  return http.request("post", `/erc/api/v1/maintain/task/queryByTaskCode/${data}`);
};
